package ace.module.tenant.core.impl.service.impl;

import ace.module.account.api.IamApplicationApi;
import ace.module.account.api.model.dto.IamApplicationDto;
import ace.module.tenant.api.constant.TenantConstant;
import ace.module.tenant.core.impl.service.TenantService;
import ace.module.upms.api.UpmsApplicationApi;
import ace.module.upms.api.model.dto.UpmsApplicationDto;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@AllArgsConstructor
@Component
public class TenantServiceImpl implements TenantService {
  private final IamApplicationApi iamApplicationApi;
  private final UpmsApplicationApi upmsApplicationApi;

  @Override
  public IamApplicationDto getTenantIamAppByTenantId(Long tenantId) {
    return this.iamApplicationApi
        .getAndCheckByOutTypeAndOutId(TenantConstant.TENANT_IAM_APP_OUT_TYPE, tenantId.toString())
        .check();
  }

  @Override
  public UpmsApplicationDto getTenantUpmsAppByTenantId(Long tenantId) {
    return this.upmsApplicationApi
        .getAndCheckByOutTypeAndOutId(TenantConstant.TENANT_IAM_APP_OUT_TYPE, tenantId.toString())
        .check();
  }
}
